import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';

class FormMultipleInputItem extends StatelessWidget {
  const FormMultipleInputItem({
    this.key,
    this.title,
    this.placeholder,
    this.noEmpty,
    this.content,
    this.onChangeCallback,
    this.onSaveCallback,
    this.controller,
    this.focusNode,
  }) : super(key: key);

  final Key key;

  final FocusNode focusNode;

  /// 标题
  final String title;

  /// 占位符
  final String placeholder;

  /// 是否必须有值
  final bool noEmpty;

  /// 内容
  final String content;

  /// 文本框输入内容改变的回调
  final ValueChanged onChangeCallback;

  /// 表单提交时回调
  final FormFieldSetter onSaveCallback;

  /// controller
  final TextEditingController controller;

  @override
  Widget build(BuildContext context) {
    return _getMultipleInputItem(context);
  }

  /// 获取选择类型item
  Widget _getMultipleInputItem(BuildContext context) {
    return Container(
        margin: EdgeInsets.symmetric(
            vertical: ScreenAdapter.height(20),
            horizontal: ScreenAdapter.width(30)),
        child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Text(title,
                  style: TextStyle(
                      color: ThemeColors.colorType1,
                      fontSize: ScreenAdapter.sp(30))),
              SizedBox(height: ScreenAdapter.height(30)),
              Container(
                height: ScreenAdapter.height(170),
                padding: EdgeInsets.only(
                    left: ScreenAdapter.width(30),
                    right: ScreenAdapter.width(30)),
                decoration: BoxDecoration(
                    border: new Border.all(
                        width: 1, color: ThemeColors.colorType39),
                    borderRadius:
                        BorderRadius.circular(ScreenAdapter.width(10))),
                child: TextFormField(
                  decoration: InputDecoration(
                      hintText: placeholder, border: InputBorder.none),
                  style: TextStyle(
                    color: ThemeColors.colorType4,
                    fontSize: ScreenAdapter.sp(32),
                  ),
                  // validator: (val) {
                  //   return val.length <= 0 ? placeholder : null;
                  // },
                  keyboardType: TextInputType.text,
                  focusNode: focusNode,
                  onEditingComplete: () {
                    if (focusNode != null) {
                      FocusScope.of(context).requestFocus(focusNode);
                    }
                  },
                  onChanged: onChangeCallback,
                  onSaved: onSaveCallback,
                  textAlign: TextAlign.left,
                  maxLines: 5,
                  maxLength: 1000,
                  autofocus: false,
                  controller: controller,
                ),
              )
            ]));
  }
}
